package com.oba.king.login;

import com.oba.base.service.BaseBean;
import com.oba.base.util.MD5;
import com.oba.king.sysmanager.ModuleBean;

public class LoginBean extends BaseBean<UserInfo, LoginService> {

	private UserInfo userInfo = new UserInfo();
	private String mainPath = "/public/login.jspx";
	private String nameStr;
	private ModuleBean moduleBean;

	public void doLogin() {
		UserInfo dbUser = getService().getDao().findUserByAccount(userInfo.getAccount());
		System.out.println(userInfo.getPassword()+" -- "+dbUser.getPassword()+" -- "+MD5.getResult(userInfo.getPassword()));
		if (dbUser.getPassword().equals(MD5.getResult(userInfo.getPassword()))) {
			getSession().setAttribute(SYSTEM_USER, dbUser);
			this.userInfo = dbUser;
			mainPath = "/public/page-template.jspx";
			nameStr = "当前用户："+dbUser.getAccount();
			moduleBean.buildMenuTree(userInfo);
			goTarget("");
		} else {  // 登陆失败
			// TODO
		}
	}
	
	public void logout() {
		setSysUserNull();
		getSession().setAttribute(SYSTEM_USER, null);
		userInfo = new UserInfo();
		mainPath = "/public/login.jspx";
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	@Override
	public String doFind() {
		return null;
	}

	public String getMainPath() {
		return mainPath;
	}

	@Override
	public void init() {
		
	}

	public ModuleBean getModuleBean() {
		return moduleBean;
	}

	public void setModuleBean(ModuleBean moduleBean) {
		this.moduleBean = moduleBean;
	}

	public String getNameStr() {
		return nameStr;
	}

}
